package com.app.micaihu.view.army.adapter

import android.text.TextUtils
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.app.micaihu.R
import com.app.micaihu.configure.Config
import com.app.micaihu.configure.UmEventId
import com.app.micaihu.custom.view.AttentionView
import com.app.micaihu.utils.InteractiveUtils
import com.app.micaihu.utils.MobclickAgentUtils
import com.app.micaihu.utils.StatServiceUtils
import com.app.micaihu.view.bean.QuestionList
import com.app.micaihu.view.utils.loadCircleImage
import com.app.micaihu.view.utils.loadImage
import com.app.micaihu.view.utils.loadRadius
import com.app.utils.util.StringUtils
import com.app.utils.util.view.expression.view.BiaoQinTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 已加入军团 适配器
 */
class JoinedArmyListAdapter : BaseQuickAdapter<QuestionList.Cmt, BaseViewHolder>(R.layout.army_join_yes_list_item), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: QuestionList.Cmt) {
        StatServiceUtils.event(Config.EventBauduId.teamlist_exposure, "军团_帖子列表曝光")
        MobclickAgentUtils.event(UmEventId.topiclist_exposed, "军团")
        holder.apply {
            val attentionView = getView<AttentionView>(R.id.attentionView)
            attentionView.tag = item
            attentionView.setEventValue("军团")
            getView<ImageView>(R.id.ivHeadPic).loadCircleImage(item.headPic, R.drawable.user_head_def)
            setText(R.id.tvNickName, item.nickName)
            getView<ImageView>(R.id.ivRankIcon).loadImage(item.rankIcon, R.drawable.task_grayrank_default)
            if (com.blankj.utilcode.util.StringUtils.isEmpty(item.honourPic)) {
                getView<ImageView>(R.id.ivHonourPic).visibility = View.GONE
            } else {
                getView<ImageView>(R.id.ivHonourPic).visibility = View.VISIBLE
                getView<ImageView>(R.id.ivHonourPic).loadImage(item.honourPic)
            }
            setText(R.id.tvRankName, item.rankName)
            setText(R.id.tvArmyGroupInfo, item.armyGroupInfo)
            setText(R.id.tvPublishTime, item.publishTime)
            if (!TextUtils.isEmpty(item.title)) {
                setVisible(R.id.tvTitle, true)
                setText(R.id.tvTitle, item.title)
            } else {
                setGone(R.id.tvTitle, true)
            }
            if (!TextUtils.isEmpty(item.content)) {
                setVisible(R.id.tvContent, true)
                getView<BiaoQinTextView>(R.id.tvContent).setPicText(item.content)
            } else {
                setGone(R.id.tvContent, true)
            }

            //判断是否点赞过
            if (InteractiveUtils.getInstance().theLaudIsContains(item.id, true) && StringUtils.toInt(item.praiseNum, 0) > 0) {
                getView<TextView>(R.id.tvGood).isEnabled = false
                getView<FrameLayout>(R.id.flLand).tag = true
            } else {
                getView<TextView>(R.id.tvGood).isEnabled = true
                getView<FrameLayout>(R.id.flLand).tag = item
            }
            val bigImage = getView<ImageView>(R.id.ivBigThumb);

            val imgList = item.imgList
            if (imgList.isNullOrEmpty()) {
                setGone(R.id.flRootImageContainer, true)
            } else {
                holder.setVisible(R.id.flRootImageContainer, true)
                if (imgList.size == 1) {
                    setGone(R.id.llImageContainer3, true)
                    //设置监听
//                val autoWidthControllerListener = AutoWidthControllerListener<Any?>(bigImage)
//                LoadImageUtils.getInstance().loadImage(bigImage, imgList[0], autoWidthControllerListener)
                    bigImage.loadImage(imgList[0], R.drawable.item_big_image_holder_listpage_loading)
                } else {
                    setVisible(R.id.llImageContainer3, true)
                    bigImage.visibility = View.GONE
                    if (imgList.isNotEmpty()) {
                        getView<ImageView>(R.id.ivThumb0).loadRadius(imgList[0], 3)
                    }
                    if (imgList.size > 1) {
                        getView<ImageView>(R.id.ivThumb1).loadRadius(imgList[1], 3)
                    }
                    if (imgList.size > 2) {
                        getView<ImageView>(R.id.ivThumb2).loadRadius(imgList[2], 3)
                    }
                }
            }
            setText(R.id.tvCommentNum, item.replyNum)
            setText(R.id.tvGood, item.praiseNum)
        }

    }
}